﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Configuration;
using System.Web.Services.Protocols;

using LMSemir.Common;
namespace LMSemir.WebService
{
    public class CredentialSoapHeader : SoapHeader
    {
        /// <summary>
        /// 用户名
        /// </summary>
        public string UID { get; set; }
        /// <summary>
        /// 密码
        /// </summary>
        public string PWD { get; set; }
        /// <summary>
        /// 初始化
        /// </summary>
        /// <param name="userID">用户名</param>
        /// <param name="password">密码</param>
        public void Initial(string userID, string password)
        {
            UID = userID;
            PWD = password;
        }
        /// <summary>
        /// 检查用户验证 
        /// </summary>
        /// <param name="userID">用户名</param>
        /// <param name="password">密码</param>
        /// <param name="message">信息提示</param>
        /// <returns></returns>
        public bool IsValid(string userID, string password, out string message)
        {
            message = string.Empty;
            try
            {
                string userName = Encrypt.DecryptClient(userID);
                string userPassword = Encrypt.DecryptClient(password);
                string uid = ConfigurationManager.AppSettings["EncryptKey"];
                string pwd = ConfigurationManager.AppSettings["EncryptIV"];
                if (uid.CompareTo(userName) == 0 &&
                    pwd.CompareTo(userPassword) == 0)
                {
                    return true;
                }
                else
                {
                    message = "sorry,you have no access authority!";
                    return false;
                }
            }
            catch (Exception ex)
            {
                message = "sorry, you have no access authority" + ex.Message;
                return false;
            }
        }
        /// <summary>
        /// 检查用户验证
        /// </summary>
        /// <param name="message">信息提示</param>
        /// <returns></returns>
        public bool IsValid(out string message)
        {
            return IsValid(UID, PWD, out message);
        }
    }
}